global class ScheduledDailyAlert implements Schedulable{
   
   public static String CRON_EXP = '0 0 10 ? * MON-SAT';
   
   global void execute(SchedulableContext SC) {
       // Call method
       updateCases();
   }
   
   // Used to update case based on open more than five days and during holidays and weekends
   public void updateCases(){
       List<Case> openCases = [ Select CaseNumber, Status, Age__c, Alert_Type__c, Day__c, Status_Pending_Date__c, Status_Research_Date__c from Case where Status <> 'Closed' AND (Case_RecordTypeName__c Like 'CMS')];
       List<Holiday> holidayList = [select ActivityDate From Holiday];
       Boolean isHoliday = false;

       // used to find if today is a holiday
       for(Holiday holiday : holidayList)
           if(System.Today() == holiday.ActivityDate)
               isHoliday = true;
      
      // Iterate through the cases               
      for( Case itrCase: openCases)
      {
          // If the Case age is > 120 and the case is open
          if(itrCase.Day__c !=1 && !isHoliday && itrCase.Age__c > 120 ){
              if( itrCase.Alert_Type__c < 10){
                  itrCase.Alert_Type__c =10;
                  update itrCase;
              }    
              itrCase.Alert_Type__c += 1;
              update itrcase;
          }
                    
          // if Day is Saturday
          if(itrCase.Day__c ==1){
              if( itrCase.Status== 'Pending Acceptance')
                  itrCase.Status_Pending_Date__c +=2;
              else if( itrCase.Status== 'Research') 
                  itrCase.Status_Research_Date__c +=2;
              update itrCase;
          }
          // if Today is Holiday
          else if(isHoliday){
              if( itrCase.Status== 'Pending Acceptance')
                  itrCase.Status_Pending_Date__c +=1;
              else if( itrCase.Status== 'Research') 
                  itrCase.Status_Research_Date__c +=1;
              update itrCase;
          }                          
      
      }
   }
}